package com.jdk.demo.thread.completableFuture;

import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
import java.util.function.Supplier;

// 两个CompletionStage，谁执行返回的结果快，我就用那个CompletionStage的结果进行下一步的消耗操作
public class AcceptEitherDemo {

	public static void main(String[] args) throws Exception {
		CompletableFuture<String> future1 = CompletableFuture.supplyAsync(new Supplier<String>() {
	        @Override
	        public String get() {
	            return "hello1";
	        }
	    });
	    CompletableFuture<String> future2 = CompletableFuture.supplyAsync(new Supplier<String>() {
	        @Override
	        public String get() {
	            return "hello2";
	        }
	    });
	    future1.acceptEither(future2, new Consumer<String>() {
	        @Override
	        public void accept(String t) {
	        	System.out.println(t);
	        }
	    });
	    Thread.sleep(1000000000);
	}

}
